/*
 * MergeSegment.h
 *
 *  Created on: Feb 23, 2012
 *      Author: hxu
 */

#ifndef MERGINGSEGMENT_H_
#define MERGINGSEGMENT_H_

#include "BtreeNode.h"
#include "Point.h"


namespace Cxuh {

class MergingSegment {
	//friend class Cxuh::Btree;
public:
	MergingSegment();
	//MergingSegment(int xleft, int yleft, int xright, int yright, int zz);
	MergingSegment(Cxuh::BtreeNode *nd); // generate a ms for a sink
	MergingSegment(Cxuh::BtreeNode *nd, MergingSegment *lms, MergingSegment *rms); // generate a ms from two ms
	virtual ~MergingSegment();
	int getDistance(MergingSegment *ms);	// get the min distance between two ms
	int get_distance_comp_points(MergingSegment *ms, int& x0, int& y0, int& z0, int& x2, int& y2, int& z2); // get the closest two points compared between this and ms
	int get_distance_comp_points(MergingSegment *ms, Point<int>& pt0, Point<int>& pt2); // get the closest two points compared between this and ms
	int distance_between_pt(const Point<int>& pt) const; // get the distance between a pt and this ms
	bool intersect(MergingSegment *ms) const; // determine whether this intersect with ms
	void det_size_of_TRR(MergingSegment* lms, MergingSegment* rms, int& el, int& er);//determine the length of el and er, which are the size of TRR for lms and rms
	//void mergeTRR(TRR *trr1, TRR *trr2);
	int get_slope() const;
	Point<int> get_left_point() const;
	Point<int> get_right_point() const;
	void set_left_point(const Point<int>& pt);
	void set_right_point(const Point<int>& pt);
private:
	int xl, xr, yl, yr, z; // point (xl, yl) is on the left
	int l; // length
	int slope;
	Cxuh::BtreeNode *node; // the corresponding node
	Cxuh::Point<int> pointl, pointr; // left and right points
	double dmin, dmax; // downstream delays
	double Cin; // input capacitance

	// func
	void initialization(); // used for all constructors
};

} /* namespace Cxuh */
#endif /* MERGESEGMENT_H_ */
